const isPro = process.env.NODE_ENV === 'production'
const CompressionPlugin = require('compression-webpack-plugin')
const path = require('path')
const resolve = dir => {
    return path.join(__dirname, dir)
}
function addStyleResource (rule) {
    rule.use('style-resource')
        .loader('style-resources-loader')
        .options({
            patterns: [path.resolve(__dirname, "./src/assets/less/base/variables.less")]
        })
}
module.exports = {
    devServer: {
        port: 8090,
        proxy: {
            '/local': {
                target: 'http://192.168.1.16:5008', // 这里去修改代理地址
                changeOrigin: true,
                ws: true,
                pathRewrite: {
                    '^/local': ''
                }
            }
        }
    },
    publicPath: '/',
    chainWebpack: config => {
        config.entry('index').add('babel-polyfill')
        config.resolve.alias
            .set('@', resolve('src'))
            .set('_com', resolve('src/components'))
            .set('_pageCom', resolve('src/views/components'))
        const types = ['vue-modules', 'vue', 'normal-modules', 'normal']
        types.forEach(type => addStyleResource(config.module.rule('less').oneOf(type)))
    },
    configureWebpack: config => {
        if (isPro) {
            return {
                plugins: [new CompressionPlugin({
                    test: /\.js$|\.html$|\.css/,
                    threshold: 10240,
                    deleteOriginalAssets: false
                })]
            }
        }
    }
}
